package com.shine.icis.action;

import java.util.Collection;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.esim.struts.webutil.SessionParam;
import com.shine.icis.blo.IBusinessConfService;
import com.shine.icis.config.SysCodeDictLoader;
import com.shine.icis.config.SysConstants;
import com.shine.icis.hbean.BusinessConf;
import com.shine.icis.hbean.SubmitConf;
import com.shine.icis.util.EFRameInf;

public class BusinessConfAction extends BaseAction {

	/**
	 * A13全业务配置
	 */
	private static final long serialVersionUID = 7638121893867812633L;
	
	private IBusinessConfService businessConfService;
	
	// input param
	private int pageNo;
	private int pageSize;
	private int busiId; 
	private String busiName;//业务名称
	private String enableFlag;//是否启用
	private String confType;//配置类型
	private String confValue;//配置值
	private String note;//说明
	
	//output value
	private ListPage<BusinessConf> businessConfPage;
	private Collection<SubmitConf> submitConfs;
	
	public void setBusinessConfService(IBusinessConfService businessConfService) {
		this.businessConfService = businessConfService;
	}
	
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setBusiId(int busiId) {
		this.busiId = busiId;
	}

	public void setBusiName(String busiName) {
		this.busiName = busiName;
	}

	public void setEnableFlag(String enableFlag) {
		this.enableFlag = enableFlag;
	}

	public void setConfType(String confType) {
		this.confType = confType;
	}

	public void setConfValue(String confValue) {
		this.confValue = confValue;
	}
	
	public void setNote(String note) {
		this.note = note;
	}

	public ListPage<BusinessConf> getBusinessConfPage() {
		return businessConfPage;
	}
	
	public Collection<SubmitConf> getSubmitConfs() {
		return submitConfs;
	}

	/**
	 * 进入查询页面
	 * @return
	 */
	public String initQueryBusinessConf() {
		return success();
	}
	
	/**
	 * 查询
	 * @return
	 */
	public String queryBusinessConf() {
		QueryParameters qp = new QueryParameters();
		
		//设置分页信息
		qp.setPageNo(pageNo);
		qp.setPageSize(pageSize);
		//排序信息
//		qp.addOrder("busiName", false);
		qp.addOrder("busiId", true);
		//参数
		if(busiName != null && !busiName.trim().equals("")) {
			qp.addParameter("busiName", busiName);
		}
		if(enableFlag != null && !enableFlag.trim().equals("")) {
			qp.addParameter("enableFlag", "1".equals(enableFlag));
		}
		try {
			businessConfPage = businessConfService.getBusinessConfPage(qp);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String modifyBusinessConf() {
		if (confValue == null || confValue.trim().equals("")
				|| enableFlag == null || enableFlag.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			businessConfService.modifyBusinessConf(busiId, confValue, "1".equals(enableFlag), note);
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BUSICONF, "修改应收应付全业务配置，业务ID为[" + busiId + "]", success);
		}
//		System.out.println(busiId + "--" + confValue + "--" + enableFlag + "----------" );
//		return success();
	}
	
	/**
	 * 加载值类型列表
	 * @return
	 */
	public String loadConfTypes() {
		try {
			submitConfs = SysCodeDictLoader.getInstance().getBusinessConfs(confType);
		return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
}
